﻿package mortal.game.view.ranking.view
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.gengine.utils.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.platform.*;
    import mortal.game.view.ranking.data.*;
    import mortal.game.view.ranking.renderer.*;
    import mortal.game.view.ranking.util.*;
    import mortal.mvc.core.*;

    public class RankingDataInfoSpr extends GSprite
    {
        private var _headInfo1:GTextFiled;
        private var _headInfo2:GTextFiled;
        private var _headInfo3:GTextFiled;
        private var _headInfo4:GTextFiled;
        private var _headInfo5:GTextFiled;
        private var _rankingInfoList:GTileList;
        private var _myRankLink:GTextFiled;
        private var _pageSelecter:PageSelecter;
        private var _pageText:GTextInput;
        private var _jumpBtn:GButton;
        private var _infoSpr:GSprite;
        private var _rankListData:Array;
        private var _currRankType:int;
        private var _headInfoVec:Vector.<GTextFiled>;
        private var _currSelRankData:SToplist;

        public function RankingDataInfoSpr()
        {
            this._headInfoVec = new Vector.<GTextFiled>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(0, 2, 462, 23, this, ImagesConst.RegionTitleBg));
            this._infoSpr = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._infoSpr);
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41345), 389, 2, 33, 20, this._infoSpr));
            this._headInfo1 = UIFactory.gTextField("", 48, 2, 70, 20, this._infoSpr);
            this._headInfo2 = UIFactory.gTextField("", 113, 2, 70, 20, this._infoSpr);
            this._headInfo3 = UIFactory.gTextField("", 206, 2, 70, 20, this._infoSpr);
            this._headInfo4 = UIFactory.gTextField("", 300, 2, 70, 20, this._infoSpr);
            this._headInfo5 = UIFactory.gTextField("", 389, 2, 70, 20, this._infoSpr);
            this._headInfoVec.push(this._headInfo1);
            this._headInfoVec.push(this._headInfo2);
            this._headInfoVec.push(this._headInfo3);
            this._headInfoVec.push(this._headInfo4);
            this._headInfoVec.push(this._headInfo5);
            this._rankingInfoList = UIFactory.tileList(0, (25 + 1), 462, 460, this);
            this._rankingInfoList.columnWidth = 461 - 4;
            this._rankingInfoList.rowHeight = 44 - 1;
            this._rankingInfoList.horizontalGap = 0;
            this._rankingInfoList.verticalGap = 1;
            this._rankingInfoList.setStyle("skin", new Bitmap());
            this._rankingInfoList.setStyle("cellRenderer", RankingDataCellRenderer);
            this._rankingInfoList.configEventListener(MouseEvent.CLICK, this.onListClickHandler);
            this._myRankLink = UIFactory.gTextField("", 18 - 2, 398 + 76, 57, 20, this);
            this._myRankLink.htmlText = HTMLUtil.addLink(Language.getString(41346), GlobalStyle.colorLv);
            this._myRankLink.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._myRankLink.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._pageSelecter = UIFactory.pageSelecter(153 - 2, 400 + 76, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.InputBg, _loc_1);
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._pageText = UIFactory.gTextInput(337 - 2, 399 + 76, 44, 23, this);
            _loc_1.align = AlignMode.CENTER;
            this._pageText.setStyle("textFormat", _loc_1);
            this._jumpBtn = UIFactory.gButton(Language.getString(41347), 382 - 2, 399 + 76, 55, 23, this);
            this._jumpBtn.configEventListener(MouseEvent.CLICK, this.onJumpClickHandler);
            this._myRankLink.configEventListener(TextEvent.LINK, this.onLinkClickHandler);
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            Dispatcher.addEventListener(EventName.RankingGetListBySearch, this.getListByConditionHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            Dispatcher.removeEventListener(EventName.RankingGetListBySearch, this.getListByConditionHandler);
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            var _loc_2:* = param1 as Array;
            var _loc_3:* = new DataProvider();
            var _loc_4:int = 0;
            while (_loc_4 < _loc_2.length)
            {
                
                _loc_3.addItem(_loc_2[_loc_4]);
                _loc_4++;
            }
            this._rankingInfoList.dataProvider = _loc_3;
            this._rankingInfoList.selectedIndex = -1;
            this._rankingInfoList.drawNow();
            return;
        }// end function

        public function updataHeadInfo() : void
        {
            var _loc_1:Array = null;
            var _loc_2:GTextFiled = null;
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            this.clearHead();
            switch(this._currRankType)
            {
                case EToplistType._EToplistTypePlayerLevel:
                {
                    _loc_1 = Language.getArray(40404);
                    if (PlatformConst.isQQ())
                    {
                        this._infoSpr.x = 33;
                    }
                    break;
                }
                case EToplistType._EToplistTypePlayerCombat:
                {
                    _loc_1 = Language.getArray(40403);
                    if (PlatformConst.isQQ())
                    {
                        this._infoSpr.x = 35;
                    }
                    break;
                }
                case EToplistType._EToplistTypePlayerSpriteCombat:
                {
                    _loc_1 = Language.getArray(40405);
                    break;
                }
                case EToplistType._EToplistTypeEquipWeapon:
                {
                    _loc_1 = Language.getArray(40406);
                    break;
                }
                case EToplistType._EToplistTypeEquipArmor:
                {
                    _loc_1 = Language.getArray(40407);
                    break;
                }
                case EToplistType._EToplistTypeEquipJewelry:
                {
                    _loc_1 = Language.getArray(40407);
                    break;
                }
                case EToplistType._EToplistTypePetCombat:
                {
                    _loc_1 = Language.getArray(40408);
                    break;
                }
                case EToplistType._EToplistTypePetGrowth:
                {
                    _loc_1 = Language.getArray(40410);
                    break;
                }
                case EToplistType._EToplistTypeMountCombat:
                {
                    _loc_1 = Language.getArray(40413);
                    break;
                }
                case EToplistType._EToplistTypeMountRank:
                {
                    _loc_1 = Language.getArray(40412);
                    break;
                }
                case EToplistType._EToplistTypeGuildCombat:
                {
                    _loc_1 = Language.getArray(40416);
                    break;
                }
                case EToplistType._EToplistTypeGuildLevel:
                {
                    _loc_1 = Language.getArray(40415);
                    break;
                }
                case EToplistType._EToplistTypeFashion:
                {
                    _loc_1 = Language.getArray(40417);
                    break;
                }
                case EToplistType._EToplistTypeWing:
                {
                    _loc_1 = Language.getArray(40418);
                    break;
                }
                case EToplistType._EToplistTypeWeapon:
                {
                    _loc_1 = Language.getArray(40419);
                    break;
                }
                case EToplistType._EToplistTypeFightSoul:
                {
                    _loc_1 = Language.getArray(40420);
                    break;
                }
                case EToplistType._EToplistTypeFightMethod:
                {
                    _loc_1 = Language.getArray(40421);
                    break;
                }
                case EToplistType._EToplistTypeFightDragonSoul:
                {
                    _loc_1 = Language.getArray(40422);
                    break;
                }
                case EToplistType._EToplistTypeCopyDefence20:
                {
                    _loc_1 = Language.getArray(40423);
                    break;
                }
                case EToplistType._EToplistTypeCopyTower:
                {
                    _loc_1 = Language.getArray(40424);
                    break;
                }
                case EToplistType._EToplistTypeCopyChallenge:
                {
                    _loc_1 = Language.getArray(40425);
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (this._currRankType == 404)
            {
                for each (_loc_2 in this._headInfoVec)
                {
                    
                    _loc_2.text = "";
                }
            }
            else
            {
                _loc_3 = RankingUtil.getPosInfoByRankType(this._currRankType);
                _loc_4 = 0;
                while (_loc_4 < _loc_1.length)
                {
                    
                    this._headInfoVec[_loc_4].text = _loc_1[_loc_4].label;
                    this._headInfoVec[_loc_4].x = _loc_3[_loc_4];
                    _loc_4++;
                }
            }
            return;
        }// end function

        public function updateAllInfo(param1:Array) : void
        {
            this._rankListData = param1;
            this.updatePageInfo(param1);
            this.updateRankInfo();
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateRankInfo();
            return;
        }// end function

        private function onJumpClickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = int(this._pageText.text);
            if (_loc_2 < 1 || _loc_2 > this._pageSelecter.maxPage)
            {
                return;
            }
            this._pageSelecter.currentPage = _loc_2;
            this.updateRankInfo();
            return;
        }// end function

        private function onLinkClickHandler(event:TextEvent) : void
        {
            var _loc_2:* = Cache.instance.role.entityInfo.name;
            var _loc_3:* = Cache.instance.ranking.getRankingInfoByName(this._currRankType, _loc_2);
            if (_loc_3.pageInList != -1 && _loc_3.rankingData)
            {
                this._rankListData = Cache.instance.ranking.getRankingDataByType(this._currRankType);
                this.updatePageInfo(this._rankListData);
                this._pageSelecter.currentPage = _loc_3.pageInList;
                this.updateRankInfo();
                Dispatcher.dispatchEvent(new DataEvent(EventName.RankingLookSelfRankInfo));
                if (!this.judgeIsCurrRankData(_loc_3.rankingData))
                {
                    this._currSelRankData = _loc_3.rankingData;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.RankingLookRoleInfo, this._currSelRankData));
                }
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(41348));
            }
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        private function onListClickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = this._rankingInfoList.selectedItem as SToplist;
            if (!this.judgeIsCurrRankData(_loc_2))
            {
                this._currSelRankData = _loc_2;
                Dispatcher.dispatchEvent(new DataEvent(EventName.RankingLookRoleInfo, this._currSelRankData));
            }
            return;
        }// end function

        private function judgeIsCurrRankData(param1:SToplist) : Boolean
        {
            var _loc_2:String = null;
            if (this._currSelRankData)
            {
                if (this._currSelRankData.toplistType == EToplistType._EToplistTypePlayerLevel || this._currSelRankData.toplistType == EToplistType._EToplistTypePlayerCombat || this._currSelRankData.toplistType == EToplistType._EToplistTypePlayerSpriteCombat)
                {
                    _loc_2 = "entityId";
                }
                else
                {
                    _loc_2 = "ownerId";
                }
                if (this._currSelRankData[_loc_2] == param1[_loc_2])
                {
                    return true;
                }
            }
            return false;
        }// end function

        private function updatePageInfo(param1:Array) : void
        {
            this._pageSelecter.maxPage = Math.ceil(param1.length / RankingConst.PageSize);
            this._pageSelecter.currentPage = 1;
            return;
        }// end function

        private function updateRankInfo() : void
        {
            var _loc_1:* = (this._pageSelecter.currentPage - 1) * RankingConst.PageSize;
            var _loc_2:* = this._pageSelecter.currentPage * RankingConst.PageSize;
            var _loc_3:* = this._rankListData.slice(_loc_1, _loc_2);
            this.data = _loc_3;
            return;
        }// end function

        private function getListByConditionHandler(event:DataEvent) : void
        {
            var _loc_3:Array = null;
            var _loc_4:String = null;
            var _loc_2:* = event.data;
            if (this._currRankType == 0)
            {
                MsgManager.showRollTipsMsg(Language.getString(41349));
                return;
            }
            if (_loc_2 is String)
            {
                _loc_4 = _loc_2 as String;
                _loc_3 = Cache.instance.ranking.getRankingDataByName(this._currRankType, _loc_4);
                if (_loc_3.length == 0)
                {
                    MsgManager.showRollTipsMsg(Language.getString(41350));
                    return;
                }
            }
            else
            {
                _loc_3 = Cache.instance.ranking.getRankingDataByCondition(this._currRankType, _loc_2.career, _loc_2.camp, _loc_2.sex);
            }
            this.updateAllInfo(_loc_3);
            return;
        }// end function

        private function clearHead() : void
        {
            this._headInfo1.text = "";
            this._headInfo2.text = "";
            this._headInfo3.text = "";
            this._headInfo4.text = "";
            this._headInfo5.text = "";
            this._infoSpr.x = 0;
            return;
        }// end function

        public function clear() : void
        {
            this._currSelRankData = null;
            this._currRankType = 0;
            this._rankingInfoList.dataProvider = new DataProvider();
            this._rankingInfoList.drawNow();
            this._pageSelecter.maxPage = 0;
            this._pageText.text = "";
            return;
        }// end function

        public function set currRankType(param1:int) : void
        {
            this._currRankType = param1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._headInfo1.dispose(param1);
            this._headInfo2.dispose(param1);
            this._headInfo3.dispose(param1);
            this._headInfo4.dispose(param1);
            this._headInfo5.dispose(param1);
            this._rankingInfoList.dispose(param1);
            this._myRankLink.dispose(param1);
            this._pageSelecter.dispose(param1);
            this._pageText.dispose(param1);
            this._jumpBtn.dispose(param1);
            this._infoSpr.dispose();
            this._headInfo1 = null;
            this._headInfo2 = null;
            this._headInfo3 = null;
            this._headInfo4 = null;
            this._headInfo5 = null;
            this._rankingInfoList = null;
            this._myRankLink = null;
            this._pageSelecter = null;
            this._pageText = null;
            this._jumpBtn = null;
            this._infoSpr = null;
            this._currSelRankData = null;
            this._headInfoVec.length = 0;
            this.removeListeners();
            return;
        }// end function

    }
}
